<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/10/30
  Time: 9:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<h1 id="hid" align="center">商品列表</h1>
<%--搜索框:模糊查询--%>
<div style="text-align: center">
    <form action="${pageContext.request.contextPath}/conditionServlet" method="post">
        <input type="text" name="condition" value="${c}">
        <input type="submit"  value="搜索">
    </form>
</div>
<%--添加商品--%>
<hr>
<div id="tp" align="center"><a href="${pageContext.request.contextPath}/cart/add.jsp">添加</a></div>
<%--商品列表--%>
<form action="" >
    <table align="center" border="1" cellspacing="0" width="800px" id="tbox">
        <tr>
            <td>序号</td>
            <td>商品名称</td>
            <td>商品价格</td>
            <td>操作</td>
        </tr>
        <c:forEach var="p" items="${page.pageList}" varStatus="status">
            <c:choose>
                <c:when test="${status.count%2==0}">
                    <tr style="background-color: gray">
                        <td>${status.count}</td>
                        <td>${p.pname}</td>
                        <td>${p["market_price"]}</td>
                        <td><a href="${pageContext.request.contextPath}/showPageServlet?pid=${p.pid}&curren=${page.currenPage}">修改</a>
                            <a href="${pageContext.request.contextPath}/deleteServlet?pid=${p.pid}" onclick="return confirm('确认是否删除')">删除</a></td>
                    </tr>
                </c:when>
                <c:otherwise>
                    <tr>
                        <td>${status.count}</td>
                        <td>${p.pname}</td>
                        <td>${p["market_price"]}</td>
                        <td><a href="${pageContext.request.contextPath}/showPageServlet?pid=${p.pid}&curren=${page.currenPage}">修改</a>
                            <a href="${pageContext.request.contextPath}/deleteServlet?pid=${p.pid}" onclick="return confirm('确认是否删除')">删除</a></td>
                    </tr>
                </c:otherwise>
            </c:choose>
        </c:forEach>
    </table>
    分页查询栏
    <c:choose>
        <%--当总页数小于等于10的时候，显示全部--%>
    <c:when test="${page.pageCount<=10}">
        <c:set var="begin" value="1"/>
        <c:set var="end" value="10"/>
    </c:when>
        <%--当总页数大于10的时候，只显示10页--%>
    <c:otherwise>
        <%--显示策略--%>
        <c:set var="begin" value="${page.currenPage -5}"/>
        <c:set var="end" value="${page.currenPage +4}"/>

    <c:if test="${begin<1}">
        <c:set var="begin" value="1"/>
        <c:set var="end" value="10" />
    </c:if>
    <c:if test="${end > page.pageCount}">
        <c:set var="begin" value="${page.pageCount-9}"/>
        <c:set var="end" value="${page.pageCount}"/>
    </c:if>
    </c:otherwise>
    </c:choose>


    <div align="center">
        第${page.currenPage}页/共${page.pageCount}页
        <hr>
        <c:if test="${page.currenPage>1}">
            <a href="${pageContext.request.contextPath}/pageServlet?currenPage=${page.currenPage-1}">上一页</a>
        </c:if>
        <c:forEach var="num" begin="${begin}" end="${end}">
            <c:choose>
                <c:when test="${num==page.currenPage}">
                    ${num}
                </c:when>
                <c:otherwise>
                    <a href="${pageContext.request.contextPath}/pageServlet?currenPage=${num}">[${num}]</a>
                </c:otherwise>
            </c:choose>
        </c:forEach>
        <c:if test="${page.currenPage<page.pageCount}">
            <a href="${pageContext.request.contextPath}/pageServlet?currenPage=${page.currenPage+1}">下一页</a>
        </c:if>
        <hr>
        <div>
            <a href="${pageContext.request.contextPath}/pageServlet?currenPage=1">首页</a>
            <a href="${pageContext.request.contextPath}/pageServlet?currenPage=${page.pageCount}">尾页</a>
        </div>
    </div>

</body>
</html>
